package com.shuxinxin.test.controller;


import com.shuxinxin.test.mapper.BookMapper;
import com.shuxinxin.test.mapper.UserMapper;
import com.shuxinxin.test.pojo.Book;
import com.shuxinxin.test.pojo.Result;
import com.shuxinxin.test.service.BookService;
import com.shuxinxin.test.utils.JwtUtil;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookService bookService;

    @GetMapping("/query")
    public Result queryBook(Book book) {

        List<Book> books = bookService.queryBook(book);
        return Result.success(books);
    }

    @GetMapping("/queryAll")
    public Result queryBookAll(){

        List<Map<String, Object>> books = bookService.queryAll();
        return Result.success(books);
    }

//    修改图书
    @PostMapping("/updatebook")
    public Result updateBook( Book book,@RequestHeader(name="Authorization")String token){
//        token
        Map<String, Object> map = JwtUtil.parseToken(token);
        System.out.println(book+"_____________________");
        bookService.updateBook(map, book);
        return Result.success();
    }
//增加图书
    @PostMapping("/insert")
    public Result insertBook(@RequestParam Book book){

        return null;
    }

//    删除图书

//    借阅


//    归还
}
